#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 64
/*argc是命令行参数的个数*/

int main(int argc, char *argv[])
{
#if 0
    printf("argc =%d\n", argc);
    for (int i = 0; i < argc; i++)
    {
        printf("argv[%d]= %s\n", i, argv[i]);
    }
#endif

    if (argc != 3)
    {
        printf("param num error:\n");
        exit(-1);
    }

    printf("srcfile:%s\n", argv[1]);
    printf("dstfile:%s\n", argv[2]);

    const char *srcfile = argv[1];
    const char *dstfile = argv[2];
    FILE *fp1 = fopen(srcfile, "r");
    if (fp1 == NULL)
    {
        perror("open srcfile failed.");
        exit(-1);
    }

    FILE *fp2 = fopen(dstfile, "w+");
    if (fp2 == NULL)
    {
        perror("open dstfile failed.");
        exit(-1);
    }

    char buffer[BUFFER_SIZE] = {0};
    while (1)
    {
        int readBytes = fread(buffer, 1, BUFFER_SIZE - 1, fp1);
        if (readBytes < BUFFER_SIZE - 1)
        {
            fwrite(buffer, 1, readBytes, fp2);
            break;
        }

        fwrite(buffer, 1, readBytes, fp2);
        /*清除脏数据*/
        memset(buffer, 0, sizeof(buffer));
    }

    /*关闭文件 */ 
    fclose(fp1);
    fclose(fp2);

    return 0;
}
